project(patchworkpp_src)

include(GNUInstallDirs)

message("Parent project name: " ${PARENT_PROJECT_NAME})
add_library(${TARGET_NAME} STATIC src/patchworkpp.cpp)
set_target_properties(${TARGET_NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON)

target_include_directories(${TARGET_NAME} PUBLIC
  $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
  $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
  $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
target_link_libraries(${TARGET_NAME} Eigen3::Eigen)
add_library(${PARENT_PROJECT_NAME}::${TARGET_NAME} ALIAS ${TARGET_NAME})

install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/
  DESTINATION include
)
install(TARGETS ${TARGET_NAME}
  EXPORT ${PARENT_PROJECT_NAME}Config
  LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
  ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)

export(TARGETS ${TARGET_NAME}
  NAMESPACE ${PARENT_PROJECT_NAME}::
  FILE "${CMAKE_CURRENT_BINARY_DIR}/${PARENT_PROJECT_NAME}Config.cmake"
)

# To install patchworkppConfig.cmake
install(EXPORT ${PARENT_PROJECT_NAME}Config
  DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PARENT_PROJECT_NAME}"
  NAMESPACE ${PARENT_PROJECT_NAME}::
)

# To install patchworkppTargets.cmake
install(EXPORT ${PARENT_PROJECT_NAME}Config
    DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PARENT_PROJECT_NAME}
    NAMESPACE ${PARENT_PROJECT_NAME}::
    FILE ${PARENT_PROJECT_NAME}Targets.cmake
)
